<?php
 
 class __module_user_api {
	private static $users_table = 'users';
	
	
	static function login($login, $pwd) {
 		global $init;
		
		// get needed user
			$res=drv(DB)->query("SELECT a.`acsgp`, a.`id`, a.`login` FROM `".self::$users_table."` a WHERE a.`login`=? AND a.`pwd`=? LIMIT 1", array($login, md5($pwd)));
        
		
                $user=$res->fetchRow(DB_FETCHMODE_ASSOC);
                
		        if(!empty($user['id'])) {
			        if(empty($user['access'])) $user['access'] = 990;
			        $_SESSION['user']['id']     = $user['id'];
			        $_SESSION['user']['login']  = $user['login'];
			        $_SESSION['user']['acsgp']  = $user['acsgp'];
			
			        if(isset($_COOKIE['PHPSESSID'])) {
				        $phpsessid = $_COOKIE['PHPSESSID'];
				        //setcookie("PHPSESSID", $phpsessid, ((86400)+time()));
			        }
			
			        return true;
		        } else return false;
		
                $res->free();
 	}
 	
 	
 	function get_usersTable() {
 		return self::$users_table;
 	}
 }
?>
